def isPrime(x):     
    if x == 1: return False     
    test = True     
    y = x - 1     
    while y > 1:     
        if not x % y:     
            test = False                 
            break     
        y -= 1         
    return test    
       
z = input()   
m = []   
for i in range(len(z)):   
    for y in range(i + 1,len(z) + 1):   
        x = int(z[i:y])  
        if isPrime(x):   
            m += [x]   
print(max(m) if m else 0)